﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>列表</title>
    <link href="../../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/bootstrap/css/font-awesome.css" rel="stylesheet" />
    <link href="../../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.css" rel="stylesheet"
        type="text/css" />
    <link href="../../Scripts/bootstrap/css/style.min.css" rel="stylesheet" type="text/css"
        media="all" />
    <!--jquery-->
    <script src="../../Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="../../Comm/JS/layer/layer.js" type="text/javascript"></script>
    <link href="../../Comm/JS/layer/layer.css" rel="stylesheet" type="text/css" />
    <!--bootstrap-table-->
    <script src="../../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.js" type="text/javascript"></script>
    <script src="../../Scripts/bootstrap/bootstrap-table/src/locale/bootstrap-table-zh-CN.js"
        type="text/javascript"></script>
    <script src="../../Scripts/bootstrap/BootstrapUIDialog.js" type="text/javascript"></script>
    <script src="../../Scripts/bootstrap/bootstrap-paginator/js/bootstrap-paginator.js"
        type="text/javascript"></script>
    <!--公共JS-->
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script language="JavaScript" src="../../Comm/JScript.js" type="text/javascript"></script>
    <script src="../../Comm/JS/Calendar/WdatePicker.js" type="text/javascript"></script>
    <link href="../../Comm/JS/Calendar/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .fixed-table-container thead th .th-inner
        {
            padding: 8px;
            line-height: 24px;
            vertical-align: top;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap; /**background-color: #eaf2ff;**/
            width: 100%;
        }
        .fixed-table-header
        {
            background-color: #f2f2f2;
        }
        
        td
        {
            word-break: keep-all; /* 不换行 */
            white-space: nowrap; /* 不换行 */
            overflow: hidden; /* 内容超出宽度时隐藏超出部分的内容 */
            text-overflow: ellipsis; /* 当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用*/
            -o-text-overflow: ellipsis;
            -icab-text-overflow: ellipsis;
            -khtml-text-overflow: ellipsis;
            -moz-text-overflow: ellipsis;
            -webkit-text-overflow: ellipsis;
        }
        body
        {
            margin: 0px;
        }
        .panel-header, .panel-body
        {
            border-width: 1px;
            border-top: 0px;
            border-left: 0px;
            border-right: 0px;
        }
        
        .table
        {
            table-layout: fixed;
        }
        
        table > td
        {
            width: 100%;
        }
        .pagination
        {
            margin: 8px 0;
            display: block;
            font-size: 13px;
        }
        .pagination .controls
        {
            float: left;
            border: 0;
            padding: 7px 0 0 15px;
            color: #777;
        }
    </style>
    <script type="text/javascript">

        var webUser = null;
        var frmBill = null;
        var frmID;
   
        //分页信息
        var count = 0;//总条数
        var pageSize = 10;//一页10条
        var pages = 1; //总页数
        var pageIdx = 1;

        //查询信息
        var SearchKey="";
        var DTFrom="";
        var DTTo="";
        
        var firstLoadTable = false;

        //初始化页面
        $(function () {
            InitPage();
        });
        function InitPage(){
            webUser = new WebUser();
            if (webUser.No == null)
                return;

            frmID = GetQueryString("FrmID");

            pageIdx = GetQueryString("PageIdx");//当前页

            frmBill = new Entity("BP.Frm.FrmBill", frmID);
            document.title = frmBill.Name;

         
            //初始化查询条件
            Init_ToolBar();

            //显示查询数据
            BindTable();

            $("td").on("mouseover",function() {
                if (this.offsetWidth < this.scrollWidth) {
                    var that = this;
                    var text = $(this).text();
                   layer.tips(text, that,{
                        tips: 1,
                        time: 0
                   });
                }
              });
              $("td").on("mouseout",function(){
                layer.closeAll();
              });
            
            if(pageIdx==null || pageIdx==undefined || pageIdx == "")
                pageIdx = 1;
            //分页
            Paginator(pages,pageIdx);
        };


        function Init_ToolBar() {

            var handler = new HttpHandler("BP.Frm.WF_CCBill");
            handler.AddPara("FrmID", frmID);
            var data = handler.DoMethodReturnString("Search_ToolBar");
            if (data.indexOf('err@') == 0) {
                alert(data);
                $("#Msg").html(data);
                return;
            }
            var data = JSON.parse(data);

            //单据表单属性
            var mapData = data.Sys_MapData;
            var attrs = data.Attrs;

            var html = "";

            if (attrs.length == 0)
                html += "<table style='' >";

            if (attrs.length == 1)
                html += "<table style='width:50%;' >";

            if (attrs.length > 1)
                html += "<table style='width:100%;' >";


            html += "<tr>";
            html += "<td align='left'><input style='width:100%;' type=text id='TB_Key' placeholder='请输入关键字...' name='TB_Key' value='" +SearchKey + "' class='form-control' /></td>";
            html += "<td align='right'><label style='text-align: right; margin-top:5px;padding-left:20px;'>日期从:</label></td>";
            html += "<td align='left' style='width:160px'><input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\" style='width:160px;' class='form-control Wdate' /></td>";
            html += "<td align='right'><label>到&nbsp;&nbsp;</label></td><td align='left'><input type=text id='TB_DTTo' name='TB_DTTo' value='" + DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\"  style='width:160px;' class='form-control Wdate' /></td>";
            //增加按钮.
            html += '<td align="left" colspan=2 ><a href="#"class="btn btn-primary btn-sm" style="margin-left:20px" id="Btn_Search" onclick="Search()">查询</a>  ';
            html += "</td></tr>";

            html += "</table>";

            $("#toolBar").append(html);
        }
         //执行查询.
        function Search() {
            pageIdx = 1;
            BindTable();
        }

    
        function SearchData() {
            //创建处理器.
            var handler = new HttpHandler("BP.Frm.WF_CCBill");
            handler.AddUrlData()
            handler.AddPara("SearchKey",$("#TB_Key").val());
            handler.AddPara("DTFrom",$("#TB_DTFrom").val());
            handler.AddPara("DTTo",$("#TB_DTTo").val());
            handler.AddPara("SearchKey",$("#TB_Key").val());
            handler.AddPara("PageIdx", pageIdx);
            handler.AddPara("PageSize", pageSize);

            //查询集合
            var data = handler.DoMethodReturnString("Search_Init");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            data = JSON.parse(data);

     

            count = data["DT"].length;
            if (count%pageSize!=0)
                pages = parseInt(count / pageSize) + 1;
            else
                pages = parseInt(count / pageSize);

            if(pages == 0) pages =1;

             if (firstLoadTable){
                $('#dg').bootstrapTable("load",data["DT"]);
                return;
           }
            return data;
        }

        //生成查询页面..
        function BindTable() {
           
            //获取页面的高度
            var H = document.body.clientHeight;
            var tableH = H-$("#toolbar").outerHeight()-$("#page-nav").outerHeight()-70;

            if (pageIdx == "" || pageIdx == undefined)
                pageIdx = "1";
            if (pageSize == "" || pageSize == undefined)
                pageSize = "20";


            var mapdata = SearchData();
            var attrs = mapdata["Attrs"];

            if (attrs == undefined) {
                alert('没有取得属性.');
                return;
            }

            var keyOfEn = "";

            var columns = new Array(); 
            
           columns.push({
                title: '序',
                field: '',
                align: 'center',
                width:25,
                formatter: function (value, row, index) {
                    return pageSize * (pageIdx - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
                }
           });
            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];

                if (attr.UIVisible == 0
                || attr.KeyOfEn == "OID"
                || attr.KeyOfEn == "WorkID"
                || attr.KeyOfEn == "NodeID"
                || attr.KeyOfEn == "MyNum"
                || attr.KeyOfEn == "MyPK") {
                    keyOfEn = attr.KeyOfEn
                    continue;
                }


                var field = attr.KeyOfEn;
                var title = attr.Name;
                var width = attr.Width;

                if(field == "BillState"){
                  columns.push({
                        field: field,
                        title: title,
                        width:attr.Width,
                        fixed: false,
                        formatter: function (value, row, index) {
                            return GetBillState(value);
                        }
                    });
                    continue;
                }

                if(field == "Title"){
                  columns.push({
                        field: field,
                        title: title,
                        width:attr.Width,
                        fixed: false,
                        formatter: function (value, row, index) {
                            var icon = GenerICON(false, row.BillState);
                            return "<a href=\"javaScript:RefBill_Done('" + row.OID + "')\"><img src=" + icon + " border=0 width='14px;' />" +value + "</a>";
                        }
                    });
                    continue;
                }

                if (attr.UIContralType == 1 || attr.UIContralType == 3){
                    if(width==null || width==""|| width==undefined)
                        width = 180;
                    if(attr.LGType == 0)
                        field = field +"T";
                    else
                        field = field + "Text";

                     columns.push({
                        field: field,
                        title: title,
                        fixed: false,
                        width:width,
                        cellStyle:{
                            css:{"white-space": "nowrap","word-break":"keep-all",  "width":"100%"}
                        }
                    });
                    continue;
                }
                if (attr.UIContralType == 2){
                    columns.push({
                        field: field,
                        title: title,
                        width:attr.Width,
                        fixed: false,
                        formatter: function (value, row, index) {
                            if (value == "0") return "否";
                            if (value == "1") return "是";
                        }
                    });
                    continue;
                }

              
                if(width==null || width==""|| width==undefined)
                    width = 100;
                columns.push({
                    field: field,
                    title: title,
                    width:attr.Width,
                    fixed: false

                });
            }
           
            $('#dg').html("");
            $('#dg').bootstrapTable({
                data: mapdata["DT"],
                columns: [columns],
                cache:false,
                striped: true,
                height:tableH,
                singleSelect: false,
                checkOnSelect:false,
                selectOnCheck:false,
                maintainSelected:true,
                sidePagination: "server",
                pageNumber: 1,
                strictSearch: true,
                //得到查询的参数
                queryParams: function (params) {
                    //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    var temp = {
                        rows: 10,                         //页面大小
                        page: (count /10) + 1,   //页码

                    };
                    return temp;
                }

            });  
             firstLoadTable = true;

     }
  
     //分页功能
    function Paginator(pageCount,currentPage) {
        var pageCount = pageCount; //取到pageCount的值(把返回数据转成object类型)
        var options = {
            bootstrapMajorVersion: 3, //版本
            currentPage: currentPage, //当前页数
            totalPages: pageCount, //总页数
            shouldShowPage: true, //是否显示该按钮
            itemTexts: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "首页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "末页";
                    case "page":
                        return page;
                }
            }, //点击事件，用于通过Ajax来刷新整个list列表
            onPageClicked: function (event, originalEvent, type, page) {
                pageIdx = page;
                SearchData(page);
               $('#page_info').html("").append("<li class='disabled controls'>当前第" + pageIdx + "页，总共" + pages +
                                "页,总共"+count+"条记录。</li>");
            }
        };
        $('#page_nav').bootstrapPaginator(options);
        $('#page_info').append("<li class='disabled controls'>当前第" + pageIdx + "页，总共" + pages +
                                "页,总共"+count+"条记录。</li>");
        
    }
   function GenerICON(isCanDo, BillState) {

        if (BillState == 3)
            icon = "../Img/BillState/Complete.png";  //已经完成.
        else if (BillState == 2)
            icon = "./Img/BillState/Runing.png"; //运行中. 
        else if (BillState == 5)
            icon = "../Img/BillState/ReturnSta.png"; //退回.
        else
            icon = "../Img/BillState/Etc.png"; //其他.

        if (isCanDo == true && BillState != 3)
            icon = "../Img/BillState/Todo.png"; //其他.

        return icon;
    }
    function RefBill_Done(PWorkID){
        var handler = new HttpHandler("BP.Frm.WF_CCBill_Opt");
        handler.AddPara("PWorkID",PWorkID);
        handler.AddPara("PFrmID",GetQueryString("PFrmID"));
        handler.AddPara("WorkID",GetQueryString("WorkID"));
        handler.AddPara("FrmID",GetQueryString("FrmID"));
        var data = handler.DoMethodReturnString("RefBill_Done");
        if(data.indexOf("err@")!=0){
            alert(data);
            return;
        }

          $("#closeModal",parent.document).click()
    }

       
    </script>
    <style>
        /* 按钮风格 */
        input[type="button"], input[type="submit"], input[type="file"]
        {
            border: 0; /*background: #4D77A7;*/
            background: #fff;
            color: #545454;
            font-size: 12px;
            padding: 4px 15px;
            margin: 5px 3px 5px 3px;
            border-radius: 3px;
            border: 1px solid #1d7dd4;
        }
        input:hover[type="button"]
        {
            border: 0; /*background: #4D77A7;*/
            background: #1d7dd4;
            color: #fff;
            font-size: 12px;
            padding: 4px 15px;
            margin: 5px 3px 5px 3px;
            border-radius: 3px;
            border: 1px solid #1d7dd4;
        }
    </style>
</head>
<body id="SearchHtml">
    <div class="wrapper wrapper-content animated fadeInRight" style="padding: 0px 10px 0px 10px">
        <div class="ibox-content">
            <div class="row">
                <div class="panel panel-default" style="border: 0px; margin-bottom: 3px">
                    <div id="toolBar" style="width: 100%">
                    </div>
                </div>
            </div>
            <div class="row">
                <table id="dg" class="table table-hover" style="word-wrap: break-word; word-break: break-all;">
                </table>
            </div>
            <!-- 显示分页信息 -->
            <div class="row" style="text-align: left;">
                <ul class="pagination" id="page_nav">
                </ul>
                <ul class="pagination controls" id="page_info">
                </ul>
                <div style="clear: both;">
                </div>
            </div>
        </div>
        <div id="Msg">
        </div>
    </div>
</body>

</html>
